package com.senter.data.dbflow.model;

import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.OneToMany;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.list.IFlowCursorIterator;
import com.raizlabs.android.dbflow.sql.language.SQLite;
import com.raizlabs.android.dbflow.structure.BaseModel;
import com.senter.data.dbflow.db.DemoDataBase;

import java.util.List;

@Table(name = "department",database = DemoDataBase.class)
public class Department extends BaseModel {

    @PrimaryKey(autoincrement = true)
    private int id;

    @Column
    private String deptName;

    @Column
    private String deptCode;

    @Column
    private String remark;

    private List<Person> personList;

    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "personList")
    public List<Person> getPersonList(){
        if(personList == null || personList.isEmpty()) {
            personList = SQLite.select().from(Person.class).where(Person_Table.deptId.eq(getId())).queryList();
        }
        return personList;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void setPersonList(List<Person> personList) {
        this.personList = personList;
    }
}
